Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for hard links #179

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

letFunny
Copy link
Collaborator

@letFunny letFunny commented Dec 5, 2024

  • Have you signed the CLA?

Hard links can now be extracted and they are correctly reflected in the manifest.

zhijie-yang and others added 2 commits December 5, 2024 11:23
Hard links can now be extracted and they are correctly reflected in the manifest.

---------

Co-authored-by: Rafid Bin Mostofa <[email protected]>
Co-authored-by: Alberto Carretero <[email protected]>
@cjdcordeiro cjdcordeiro requested a review from niemeyer December 5, 2024 10:50
@cjdcordeiro cjdcordeiro added the Priority Look at me first label Dec 5, 2024
Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Alberto. This is looking great.

A few comments, and maybe the last pass:

internal/deb/extract.go Outdated Show resolved Hide resolved
internal/deb/extract.go Outdated Show resolved Hide resolved
internal/deb/extract.go Outdated Show resolved Hide resolved
internal/deb/extract.go Outdated Show resolved Hide resolved
hash = hex.EncodeToString(rp.h.Sum(nil))
if o.Link != "" {
err = createHardLink(o)
hardLink = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the boolean flag if we have the mode already? Looks like we've done without it for the Options, so the Entry could be the same.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an edge case where we are creating a hard link to a symlink. In that case, we are asking fsutil.Create to create an entry with o.Link = "symlink_location" and o.Mode & fs.ModeType = 0 (meaning no dir or symlink). However, the final entry will have the mode of the file that was created, if it points to symlink_location then the mode will have the symlink bit set. The problem then is that we are not able to distinguish hard link to symlink from a plain symlink because Mode and Link match both.

internal/fsutil/create_test.go Show resolved Hide resolved
@@ -18,6 +19,8 @@ type ReportEntry struct {
Slices map[*setup.Slice]bool
Link string
FinalSHA256 string
// If HardLinkID is greater than 0, all entries with the same id represent hard links to the same inode.
HardLinkID uint64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of HardLinkID/hard_link_id, I suggest naming this Inode/inode. More general idea, it's naturally an integer, and reflects the semantics in the filesystem.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't inode going to suggest there is some relationship with the physical inode in the filesystem?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline and agreed that this is a hint that this is an inode, it could in fact be the physical one.

internal/manifest/report.go Outdated Show resolved Hide resolved
internal/testutil/pkgdata.go Outdated Show resolved Hide resolved

// sanitizeTarPath removes the leading "./" from the source path in the tarball,
// and verifies that the path is not empty.
func sanitizeTarPath(path string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any logic that prevents the tar from leaving the target directory?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't at the moment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed offline to do it, just not in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority Look at me first
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants